﻿<%@ Import Namespace="CMS.Core.Domain" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MenuNav.ascx.cs" Inherits="CMS.Web.Lookups.MenuNav" %>
<script type="text/javascript"> 
$(document).ready(function(){

    //alert($("ul.subnav").parent());
	//$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").bind('mouseenter',function() { //When trigger is clicked...
	//$("ul.topnav li span").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		//$(this).parent().find("ul.subnav").fadeOut(100);

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});
</script>
<ul class="topnav">               
<% 	
    int menuId = -1;
    IList<ChucNang> cnList = null;
    foreach (ArrayList menuItem in menu)
    {
        menuId++;
        ChucNang chucNang = (ChucNang)menuItem[0];                
        
        if (chucNang.IsQuyen)
        {
            ArrayList arrList = (ArrayList)menu[menuId];
            cnList = (IList<ChucNang>)arrList[1];
            String href = "";
            String target = "";
            if (chucNang.IsLink)
            {
                href = chucNang.DuongDan;
                target = "target=\"_blank\"";
            }
            else
            {
                target = "";
                if (cnList.Count == 0)
                {
                    href = BaseUrlWithOnlyID + "&fName=" + chucNang.ID;
                }
                else
                {
                    href = "#";
                }
            }
            %>
               <li class="menu">
                    <% if (cnList.Count != 0){ %><span><a href="<%=href%>" <%=target %>><%=chucNang.TenChucNang%></a></span><%}else{ %><a href="<%=href%>" <%=target %>><%=chucNang.TenChucNang%></a><%} %>
                    <% if (cnList.Count != 0)
                       { %><ul class="subnav">
                       <%
                           foreach (ChucNang item in cnList)
                            {
                                if (item.IsLink)
                                {
                                    href = item.DuongDan;
                                    target = "target=\"_blank\"";
                                }
                                else
                                {
                                    if (item.DuongDan != "#")
                                    {
                                        href = BaseUrlWithOnlyID + "&fName=" + item.ID;
                                    }
                                    else
                                    {
                                        href = "#";
                                    }
                                    target = "";
                                }                               
                               
                                if (item.IsQuyen)
                                {
                                    %>
                                        <li><a href="<%=href%>"  <%=target %>><%=item.TenChucNang%></a></li>
                                        <%
                                }
                            }%>
                                </ul>
                            </li>
                       <%                               
                       }else{ %>                                
                        </li>
                        <%}                
        }
    }      
    %>
</ul>